/* 	
	Index of this JS File
	
	(01) Flickr Photos
	(02) Pretty Photo and Hide Boxes
	(03) Top Menu Settings
	(04) Tab Script
	(05) Simple and Accordation Toggles
	(06) Hide Information Boxes (Close Button)
	(07) Filterable Pack / Sortable Portfolio
	(08) Image Hover Fade Effect
	(09) Contact Form
	(10) Tooltip	
*/


/* ========================================================== 
	(01) Flickr Photos
============================================================ */

$(document).ready(function(){	
	$('#cbox').jflickrfeed({
		limit: 6,
		qstrings: {
			id: '52031461@N05'  /* << Replace your flickr id with theme flickr sample id */
			
			/* How to find my flickr User ID?
			You can find your flickr id from this URL : http://www.flickr.com/services/api/explore/?method=flickr.people.getInfo
			Login to your flickr account and then go to above URL. You will find your flickr id from right side in "Useful Values" section. */			
			
		},
		itemTemplate: '<li>'+
						'<a class="fade-img2" href="{{image}}" title="{{title}}" rel="prettyPhoto[flickrGallery123]">' +
							'<img src="{{image_s}}" alt="{{title}}" />' +
						'</a>' +
					  '</li>'
	}, function(data) {
		$('#cbox a').prettyPhoto();
	});
});

/* ========================================================== 
	(02) Pretty Photo and Hide Boxes
============================================================ */

$(document).ready(function(){ 
	$("a[data-rel^='prettyPhoto']").prettyPhoto(); 	 /* Pretty Photo */
	$('a[data-rel]').each(function() {
		$(this).attr('rel', $(this).data('rel'));
	});	
	hide_boxes();					 /* Infoboxes close button */	
});

/* ========================================================== 
	(03) Top Menu Settings
============================================================ */

$(document).ready(function(){ 
	$("ul.sf-menu").supersubs({ 
		minWidth:    7,   // minimum width of sub-menus in em units 
		maxWidth:    77,   // maximum width of sub-menus in em units 
		extraWidth:  -1    // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish();  // call supersubs first, then superfish, so that subs are 
					 // not display:none when measuring. Call before initialising 
					 // containing tabs for same reason. 
});

/* ========================================================== 
	(04) Tab Script
============================================================ */

$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("tab-active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("tab-active"); //Remove any "active" class
		$(this).addClass("tab-active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

/* -- */

$(document).ready(function() {

	//Default Action
	$(".tab_content2").hide(); //Hide all content
	$("ul.tabs2 li:first").addClass("tab-active2").show(); //Activate first tab
	$(".tab_content2:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs2 li").click(function() {
		$("ul.tabs2 li").removeClass("tab-active2"); //Remove any "active" class
		$(this).addClass("tab-active2"); //Add "active" class to selected tab
		$(".tab_content2").hide(); //Hide all tab content
		var activeTab2 = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab2).fadeIn(); //Fade in the active content
		return false;
	});

});


/* ========================================================== 
	(05) Simple and Accordation Toggles
============================================================ */

$(document).ready(function(){	
	// Simple Toggle script start
	$(".toggle_container").hide();
	$("p.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle(350);
	});
	
	$(".toggle_container2").hide();
	$("p.trigger2").click(function(){
		$(this).toggleClass("active2").next().slideToggle(350);
	});	
	
	//--Toggle Accrordation Script
	
	//Set default open/close settings
	$('.acc_container').hide(); //Hide/close all containers
	//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			//$(this).toggleClass('active').previous().slideUp(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container	
		}else{
			$(this).toggleClass('active').next().slideUp();
		}
		return false; //Prevent the browser jump to the link anchor
	});
	
	//Set default open/close settings
	$('.acc_container2').hide(); //Hide/close all containers
	//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger2').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger2').removeClass('active2').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			$(this).toggleClass('active2').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container	
		}else{
			$(this).toggleClass('active2').next().slideUp();
		}
		return false; //Prevent the browser jump to the link anchor
	});	
});

/* ========================================================== 
	(06) Hide Information Boxes (Close Button)
============================================================ */

$(document).ready(function(){ 	
	hide_boxes();
});

function hide_boxes(){
	$('span.hide-boxes,span.hide-boxes2').click(function() {
		$(this).parent().fadeOut();					   
	});	
}

/* ========================================================== 
	(07) Filterable Pack / Sortable Portfolio
============================================================ */

$(document).ready(function(){
	
	var $portfolioClone = $(".project-list").clone();	
	$(".filter a").click(function(e){		
		
		$(".filter li").removeClass("current");			
		
		var $filterClass = $(this).parent().attr("class");
		if ( $filterClass == "all" ) {
			var $filteredPortfolio = $portfolioClone.find("li");
		} else {
			var $filteredPortfolio = $portfolioClone.find("li[data-type~=" + $filterClass + "]");
		}
		
		$(".project-list").quicksand( $filteredPortfolio, { 
			duration: 800, 
			easing: 'easeInOutQuad' 
		}, function(){
			
				jQuery(".fade-img").show();
				jQuery(".fade-img img").fadeTo('normal', 1, function() {		
					$get_id = jQuery(this).parent().parent().attr("data-rel");
					if($get_id != ""){
						jQuery(this).parent().parent().addClass($get_id);			
						$(this).hover(function(){
						$(this).fadeTo('normal', 0.3);				
						}, function() {
							$(this).fadeTo('normal', 1);
							});
					}
				});	
				
				$("a[data-rel^='prettyPhoto']").prettyPhoto(); /* Pretty Photo */
				$('a[data-rel]').each(function() {
					$(this).attr('rel', $(this).data('rel'));
				});	
				hide_boxes(); /* Infoboxes close button */	
				
			});

		$(this).parent().addClass("current");
		
		e.preventDefault();
	})
});

/* ========================================================== 
	(08) Image Hover Fade Effect
============================================================ */

jQuery(window).load(function() { 	
	jQuery(".fade-img").show();
	jQuery(".fade-img img").fadeTo('normal', 1, function() {		
		$get_id = jQuery(this).parent().parent().attr("data-rel");
		if($get_id != ""){
			jQuery(this).parent().parent().addClass($get_id);			
			$(this).hover(function(){
				$(this).fadeTo('normal', 0.3);
				
			}, function() {
					$(this).fadeTo('normal', 1);
			});
		}
    });
});

jQuery(window).load(function() { 	
	jQuery(".fade-img2").show();
	jQuery(".fade-img2 img").fadeTo('normal', 1, function() {		
		$get_id = jQuery(this).parent().parent().attr("data-rel");
		if($get_id != ""){
			jQuery(this).parent().parent().addClass($get_id);			
			$(this).hover(function(){
				$(this).fadeTo('normal', 0.5);
				
			}, function() {
					$(this).fadeTo('normal', 1);
			});
		}
    });
});

/* ========================================================== 
	(09) Contact Form
============================================================ */

jQuery(document).ready(function(){	
	jQuery("input:text, input:password, textarea").forminput();
	jQuery("#contact_form").contact_form({
			response: "#msg",
			submit: "#submit",
			timer: 4500,
			easing: "",
			speedIn: 700,
			speedOut: 700
	});
});
// Input Field Script
(function($) {
	$.fn.forminput = function() {
		return this.each(function() {
			var $root = $(this);
			var inputValue = $root.val();
			
			function reset() {
				var value = $root.val();
				if(inputValue == value) {
					$root.val("");
				}
			}
			
			function blur() {
				var value = $root.val();
				if(value == "") {
					$root.val(inputValue);
				}
			}
			
			$root.focus(function() {
  				reset();
			});
			$root.blur(function() {
  				blur();
			});
		});
	}
})(jQuery);

// Form Script
(function($) {
	$.fn.contact_form = function(options) {
		var defaults = {
			response: "#msg",
			submit: "#submit",
			timer: 4500,
			easing: "",
			speedIn: 700,
			speedOut: 700
		};
		var options = $.extend({}, defaults, options);
		
		return this.each(function () {
			var $root = $(this);
			var $response = $(options.response);
			var $submit = $(options.submit);
			
			function showMsg($timer) {
				$response.css("opacity", 0);
				$response.show().stop().animate({
					opacity: 1
				}, options.speedIn, options.easing, function(){
					interval = setInterval(hideMsg, $timer);
				});
			}
			
			function hideMsg() {
				clearInterval(interval);
				$response.stop().animate({
					opacity:0
				}, options.speedIn, options.easing, function() {
					$response.hide();
					$submit.fadeIn(700);
				});
			}
			
			$root.submit(function(){
				$.ajax({
					type: "POST",
					url: "sendmail.php",
					data: $(this).serialize(),
					success: function(output) {
						$response.ajaxComplete(function() {
							if(output == 'ok') {
								$('#contactdiv').html("<div id='smessage'></div>");
								$('#smessage').html("<h3>Contact Form Submitted!</h3>").append("<p>We will be in touch soon.</p>").hide().fadeIn(1500, function() {
								  $('#smessage').append("");
								});
							} else {
								$(this).html(output);
								showMsg(options.timer);
							}
						});
					}
				});
				return false;
			});
		});
	}
})(jQuery);	
	

/* ========================================================== 
	(10) Tooltip
============================================================ */

$(function() {
    
    $('.tipDown').tipsy		({gravity: 'n'});
    $('.tipUp').tipsy		({gravity: 's'});
    $('.tipLeft').tipsy		({gravity: 'e'});
    $('.tipRight').tipsy	({gravity: 'w'});
	$('.tipForm').tipsy		({gravity: 's', trigger:'focus'}); 
    
  });

(function($){$.fn.tipsy=function(options){options=$.extend({},$.fn.tipsy.defaults,options);return this.each(function(){var opts=$.fn.tipsy.elementOptions(this,options);$(this).hover(function(){$.data(this,"cancel.tipsy",true);var tip=$.data(this,"active.tipsy");if(!tip){tip=$('<div class="tipsy"><div class="tipsy-inner"/></div>');tip.css({position:"absolute",zIndex:100000});$.data(this,"active.tipsy",tip);}if($(this).attr("title")||typeof($(this).attr("original-title"))!="string"){$(this).attr("original-title",$(this).attr("title")||"").removeAttr("title");}var title;if(typeof opts.title=="string"){title=$(this).attr(opts.title=="title"?"original-title":opts.title);}else{if(typeof opts.title=="function"){title=opts.title.call(this);}}tip.find(".tipsy-inner")[opts.html?"html":"text"](title||opts.fallback);var pos=$.extend({},$(this).offset(),{width:this.offsetWidth,height:this.offsetHeight});tip.get(0).className="tipsy";tip.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).appendTo(document.body);var actualWidth=tip[0].offsetWidth,actualHeight=tip[0].offsetHeight;var gravity=(typeof opts.gravity=="function")?opts.gravity.call(this):opts.gravity;switch(gravity.charAt(0)){case"n":tip.css({top:pos.top+pos.height,left:pos.left+pos.width/2-actualWidth/2}).addClass("tipsy-north");break;case"s":tip.css({top:pos.top-actualHeight,left:pos.left+pos.width/2-actualWidth/2}).addClass("tipsy-south");break;case"e":tip.css({top:pos.top+pos.height/2-actualHeight/2,left:pos.left-actualWidth}).addClass("tipsy-east");break;case"w":tip.css({top:pos.top+pos.height/2-actualHeight/2,left:pos.left+pos.width}).addClass("tipsy-west");break;}if(opts.fade){tip.css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:0.8});}else{tip.css({visibility:"visible"});}},function(){$.data(this,"cancel.tipsy",false);var self=this;setTimeout(function(){if($.data(this,"cancel.tipsy")){return;}var tip=$.data(self,"active.tipsy");if(opts.fade){tip.stop().fadeOut(function(){$(this).remove();});}else{tip.remove();}},100);});});};$.fn.tipsy.elementOptions=function(ele,options){return $.metadata?$.extend({},options,$(ele).metadata()):options;};$.fn.tipsy.defaults={fade:true,fallback:"",gravity:"n",html:true,title:"title"};$.fn.tipsy.autoNS=function(){return $(this).offset().top>($(document).scrollTop()+$(window).height()/2)?"s":"n";};$.fn.tipsy.autoWE=function(){return $(this).offset().left>($(document).scrollLeft()+$(window).width()/2)?"e":"w";};})(jQuery);

